package ${package}<#if moduleName??>.${moduleName}</#if>.controller<#if subModuleName??>.${subModuleName}</#if>;


import lombok.AllArgsConstructor;
import ${package}<#if moduleName??>.${moduleName}</#if>.entity<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Entity;
import ${package}<#if moduleName??>.${moduleName}</#if>.service<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Service;
import ${package}<#if moduleName??>.${moduleName}</#if>.query<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Query;
import org.springframework.web.bind.annotation.*;

import net.maku.generator.common.page.PageResult;
import net.maku.generator.common.utils.Result;

import javax.validation.Valid;
import java.util.Arrays;


/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@RestController
@RequestMapping("<#if moduleName??>${moduleName}/</#if>${classname}")
@AllArgsConstructor
public class ${ClassName}Controller {
    private final ${ClassName}Service ${className}Service;

    @GetMapping("page")
    public Result<PageResult<${ClassName}Entity>> page(@Valid ${ClassName}Query query){
        PageResult<${ClassName}Entity> page = ${className}Service.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    public Result<${ClassName}Entity> get(@PathVariable("id") Long id){
        ${ClassName}Entity entity = ${className}Service.getById(id);

        return Result.ok(entity);
    }

    @PostMapping
    public Result<String> save(@RequestBody ${ClassName}Entity entity){
        ${className}Service.save(entity);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody @Valid ${ClassName}Entity entity){
        ${className}Service.updateById(entity);

        return Result.ok();
    }

    @DeleteMapping
    public Result<String> delete(@RequestBody Long[] ids){
        ${className}Service.removeBatchByIds(Arrays.asList(ids));

        return Result.ok();
    }
}
